package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Shopping;
import com.ruoyi.system.service.IShoppingService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购管理Controller
 * 
 * @author 张旭
 * @date 2024-09-05
 */
@RestController
@RequestMapping("/system/shopping")
public class ShoppingController extends BaseController
{
    @Autowired
    private IShoppingService shoppingService;

    /**
     * 查询采购管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:shopping:list')")
    @GetMapping("/list")
    public TableDataInfo list(Shopping shopping)
    {
        startPage();
        List<Shopping> list = shoppingService.selectShoppingList(shopping);
        return getDataTable(list);
    }

    /**
     * 导出采购管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:shopping:export')")
    @Log(title = "采购管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Shopping shopping)
    {
        List<Shopping> list = shoppingService.selectShoppingList(shopping);
        ExcelUtil<Shopping> util = new ExcelUtil<Shopping>(Shopping.class);
        util.exportExcel(response, list, "采购管理数据");
    }

    /**
     * 获取采购管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:shopping:query')")
    @GetMapping(value = "/{shoppingSallerId}")
    public AjaxResult getInfo(@PathVariable("shoppingSallerId") Long shoppingSallerId)
    {
        return success(shoppingService.selectShoppingByShoppingSallerId(shoppingSallerId));
    }

    /**
     * 新增采购管理
     */
    @PreAuthorize("@ss.hasPermi('system:shopping:add')")
    @Log(title = "采购管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Shopping shopping)
    {
        return toAjax(shoppingService.insertShopping(shopping));
    }

    /**
     * 修改采购管理
     */
    @PreAuthorize("@ss.hasPermi('system:shopping:edit')")
    @Log(title = "采购管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Shopping shopping)
    {
        return toAjax(shoppingService.updateShopping(shopping));
    }

    /**
     * 删除采购管理
     */
    @PreAuthorize("@ss.hasPermi('system:shopping:remove')")
    @Log(title = "采购管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shoppingSallerIds}")
    public AjaxResult remove(@PathVariable Long[] shoppingSallerIds)
    {
        return toAjax(shoppingService.deleteShoppingByShoppingSallerIds(shoppingSallerIds));
    }
}
